#include("/admin/common/header.html")
#include("/admin/common/footer.html")
#include("/admin/common/left.html")
#include("/admin/common/layout.html")

 #@layout()
 #define content()

<span class="layui-breadcrumb">
  <a href="#(ctx_path)/">首页</a>
  <a href="#(ctx_path)/admin/task"><cite>定时任务管理</cite></a>
</span>

<hr>


<div class="layui-field-box">
<form class="layui-form" action="#(ctx_path)/admin/task">
    <div class="layui-form-item">
    		<div class="layui-inline">
	      <label class="layui-form-label">任务名</label>
	      <div class="layui-input-inline">
	        <input type="text" name="searchContent" autocomplete="off" class="layui-input">
	      </div>
	    </div>
	    
	    <button class="layui-btn" type="button" id="btnSearch">搜索</button>
	    <button class="layui-btn layui-btn-normal" type="reset" >重置</button>
	    <a class="layui-btn layui-btn-danger" href="#(ctx_path)/admin/task/add" >新增</a>
	    
	</div>
</form>	    
</div>
  
<table class="layui-hide" id="dataTable"></table>
  
<script type="text/html" id="actionTpl">
  	<a href="javascript:doDetail('{{d.id}}');" class="layui-table-link" actionType="detail" actionId="{{d.id}}">详情</a>
  	<a href="javascript:doStartUsing('{{d.id}}');" class="layui-table-link" >启动</a>
  	<a href="javascript:doForbidden('{{d.id}}');" class="layui-table-link" >停止</a>
  	<a href="javascript:doRunATask('{{d.id}}');" class="layui-table-link" >运行一次</a>
	
	#auth('user')
		<a href="javascript:doDelete('{{d.id}}');" class="layui-table-link">删除</a>
	#end

</script>

#end

#define js()

<script>

layui.use('table', function() {
	var table = layui.table;
	table.render({
		elem : '#dataTable',
		url : '#(ctx_path)/admin/task/pagequery',
		cols : [ [
	      {field:'jobName', title: '任务名称'},
	      {field:'cronExpression', title: 'cron表达式代码', sort: true},
	      {field:'jobStatus_dic', title: '任务状态', sort: true},
	      {field:'triggerState', title: 'triggerState', sort: true},
	      {field:'nextFireTime', title: '下次执行时间'},
	      {templet:"#actionTpl",width:'240',title: '操作'}
		] ],
		page : true
	});
	
	$("#btnSearch").click(function(){
		
		var searchContent=$(":input[name='searchContent']").val();
		//执行重载
		table.reload('dataTable', {
			page : {
				curr : 1//重新从第 1 页开始
			},
			where : {
				searchContent:searchContent,
			}
		});
		
	});
	
});


function doDetail(id){
	window.location.href="#(ctx_path)/admin/task/view?id="+id;
}

function doStartUsing(id){
	layui.layer.confirm('确认启动么?', function(index){
		$.ajax({
			type:'get',
			url:'#(ctx_path)/admin/task/startUsing',
			data:'id='+id,
			success:function(data){
				if(data.code=="0"){
					layui.table.reload('dataTable');
				}else{
					alert("失败");
				}
				
			}
		});
		layui.layer.close(index);
	}); 
}

function doForbidden(id){
	layui.layer.confirm('确认停止么?', function(index){
		$.ajax({
			type:'get',
			url:'#(ctx_path)/admin/task/forbidden',
			data:'id='+id,
			success:function(data){
				if(data.code=="0"){
					layui.table.reload('dataTable');
				}else{
					alert("失败");
				}
			}
		});
		layui.layer.close(index);
	}); 
}

function doDelete(id){
	layui.layer.confirm('确认删除么?', function(index){
		$.ajax({
			type:'get',
			url:'#(ctx_path)/admin/task/delete',
			data:'id='+id,
			success:function(data){
				if(data.code=="0"){
					layui.table.reload('dataTable');
				}else{
					alert("失败");
				}
			}
		});
		layui.layer.close(index);
	}); 
}

function doRunATask(id){
	layui.layer.confirm('确认立即运行一次么?', function(index){
		$.ajax({
			type:'get',
			url:'#(ctx_path)/admin/task/runATask',
			data:'id='+id,
			success:function(data){
				if(data.code=="0"){
					layui.table.reload('dataTable');
				}else{
					alert("失败");
				}
			}
		});
		layui.layer.close(index);
	}); 
}

</script>

#end


